<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Player
 *
 * @author Administrator
 */
class Player extends CActiveRecord{
    public function rules() {
        return array(
            array('player_name,player_alias,player_code', 'required'),
            array('player_name,player_alias', 'length', 'max' => 30),
            array('player_name,player_alias', 'unique')
        );
    }
    public function attributeLabels() {
        return array(
            'player_id' => Yii::t('default', '编号'),
            'player_name' => Yii::t('default', '播放器名称'),
            'player_alias' => Yii::t('default', '调用代码'),
            'player_code' => Yii::t('default', '播放器代码'),
            'player_create_time' => Yii::t('default', '添加时间'),
            'player_create_user' => Yii::t('default', '记录添加人'),
            'player_add_title' => Yii::t('default', '添加播放器'),
            'player_not_exists' => Yii::t('default', '播放器不存在'),
            'player_delete_failed' => Yii::t('default', '播放器删除失败')
        );
    }
    /**
     * Returns the static model of the specified AR class.
     * @return CActiveRecord the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }
    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{player}}';
    }
    public function beforeSave(){
        if( parent::beforeSave()){
            if($this->isNewRecord){
                $this->player_create_time = time();
                $this->player_create_user = Cookie::get('admin');
            }
            return true;
        }else{
            return false;
        }
    }
}